package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.response.OrdersTransferCompareResponse;
import com.ytjj.qmyx.admin.service.OrdersTransferManageService;
import com.ytjj.qmyx.mall.client.MallClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 转单管理相关接口
 * @date 2023年09月14日 9:59
 * @author jiawei
 */
@RestController
@RequestMapping("/ordersTransfer")
public class OrdersTransferManageController {

    @Autowired
    private OrdersTransferManageService transferManageService;

    /**
     * 获取转单列表
     * @param status 转单状态
     * @param pageNum
     * @param pageSize
     * @return CommonResult<CommonPage<OrdersTransferCompareResponse>>
     */
    @GetMapping("/getOrdersTransferPage")
    public CommonResult<CommonPage<OrdersTransferCompareResponse>> getOrdersTransferPage(Integer status, Integer pageNum, Integer pageSize) {
        CommonPage ordersTransferPage = transferManageService.getOrdersTransferPage(status, pageNum, pageSize);
        return CommonResult.success(ordersTransferPage);
    }

    /**
     * 新建/编辑转单
     * @param request
     * @return CommonResult<CommonPage<OrdersTransferCompareResponse>>
     */
    @PostMapping("/addOrUpdateOrdersTransfer")
    public CommonResult addOrUpdateOrdersTransfer(@RequestBody OrdersTransferCompareResponse request) {
        Integer integer = transferManageService.addOrUpdateOrdersTransfer(request);
        return integer > 0 ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 删除
     * @param ids
     * @return CommonResult
     */
    @PostMapping("/delTransferItem")
    public CommonResult delTransferItem(@RequestBody List<Integer> ids) {
        Integer integer =  transferManageService.delTransferItem(ids);
        return integer > 0 ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 更新状态
     * @param ids
     * @return CommonResult
     */
    @PostMapping("/updateTransferStatus")
    public CommonResult updateTransferStatus(@RequestBody List<Integer> ids) {
        Integer integer =  transferManageService.updateTransferStatus(ids);
        return integer > 0 ? CommonResult.success() : CommonResult.failed();
    }

    /**
     * 获取当前商品的未推送订单数
     * @param id
     * @return CommonResult
     */
    @GetMapping("/getUnPushOrdersNum")
    public CommonResult<Integer> getUnPushOrdersNum(Integer id){
        Integer unPushOrdersNum = transferManageService.getUnPushOrdersNum(id);
        return CommonResult.success(unPushOrdersNum);
    }

    /**
     * 手动转单
     * @param id 转单id
     * @param num 转单数量
     */
    @GetMapping("/toTransferOrders")
    public CommonResult toTransferOrders(Integer id,Integer num) {
        transferManageService.toTransferOrders(id, num);
        return CommonResult.success();
    }

    /**
     * 根据商品id查询商品
     * @param productId 商品id
     * @return CommonResult<ProductDetail>
     */
    @GetMapping("/getProductInfo")
    public CommonResult<OrdersTransferCompareResponse.ProductDetail> getProductInfo(Integer productId){
        OrdersTransferCompareResponse.ProductDetail productInfo = transferManageService.getProductInfo(productId);
        return CommonResult.success(productInfo);
    }

}
